{include file="public/head" /}
  
  <body>
    <div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">后台管理</a>
        <a href="">物业管理系统</a>
        <a>
          <cite>账单管理</cite></a>
      </span>
      <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
    </div>
    <div class="x-body">
      <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so"  method="get" action="{:url('admin/trade/statistic')}">

          <div class="layui-input-inline" style="width:200px">
            <input class="layui-input" placeholder="开始时间" name="start_time" id="start" {if isset($start_time)}value="{$start_time}"{/if} style="width:180px">
            </div>
          <div class="layui-input-inline" style="width:200px">
          <input class="layui-input" placeholder="结束时间" name="end_time" id="end" {if isset($end_time)}value="{$end_time}"{/if}  style="width:180px">
          </div>
          <input class="layui-input" placeholder="小区名称" name="community_name" id="community_name" {if isset($community_name)}value="{$community_name}"{/if} >
          <button class="layui-btn"  lay-submit="submit" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
        </form>
      </div>
      <xblock>

        <button class="layui-btn layui-btn-danger" onclick="exportExcel('{$export}')"><i class="layui-icon"></i>批量导出</button>

        <span class="x-right" style="line-height:40px"> 共有数据： {$number}  条</span>
      </xblock>
      <table class="layui-table"  id="table">
        <thead>
          <tr>
            <th style="text-align: center; font-size: 16px;">小区名</th>
            <th style="text-align: center; font-size: 16px;">商铺</th>
            <th style="text-align: center; font-size: 16px;">日期</th>
            <th style="text-align: center; font-size: 16px;">支付宝</th>
            <th style="text-align: center; font-size: 16px;">微信</th>
            <th style="text-align: center; font-size: 16px;">合计</th>
            </tr>
        </thead>
        <tbody>
          {foreach $list as $val}
          <tr>
            <td style="text-align: center;">{$val.community_name}</td>
            <td style="text-align: center;">{$val.store_name}</td>
            <td style="text-align: center;">{$val.date}</td>
            <td style="text-align: center;">{$val.money_alipay}</td>
            <td style="text-align: center;">{$val.money_wechat}</td>

            <td style="text-align: center;"> {$val.money}</td>

          </tr>
          {/foreach}
        </tbody>
      </table>
      <div class="page">
        <div>
          {$pageRender|raw}
        </div>
      </div>

    </div>
    <script>
      layui.use('laydate', function(){
        var laydate = layui.laydate;
        
        //执行一个laydate实例
        laydate.render({
          elem: '#start', //指定元素
          type:'datetime',
        });

        //执行一个laydate实例
        laydate.render({
          elem: '#end' //指定元素
          ,type:'datetime',
        });
      });
      function cancellation(id, doc){
        if(confirm('是否确定冲红?')) 
        { 

          var url = "{:url('invoice/Cancellation')}?id=" + id
          // console.log(url)
          $('#red' + doc).attr('href', url)
        } 
          return false; 
      }
        //删除
      
      function billDelId(id, doc){
        if(confirm('删除后无法恢复，确定要删除吗?')) 
        { 
          var url = "{:url('billDelId')}?id=" + id
          // console.log(url)
          $('#' + doc).attr('href', url)
        } 
          return false; 
      } 

      //批量删除
      function delAll () {
        var datas = $('#table tbody td .layui-form-checked')
        var ids = []
        datas.each(function(index, element){
          var id = $(this).data('id')
          ids.push(id)
        })

        var str = ids.join(',');
        var count = ids.length
        //window.location.href='{:url("billDel")}?id='+str;
        layer.confirm('你确定要删除这'+ count + '项吗', function(){
          $.post('{:url("billDel")}', { id: str}, function(r){
            if (r.info) {
              layer.msg(r.info)
              location.reload()
            }else{
              layer.msg(r.error)
              location.reload()
            }
          })
        })
      }
    //批量删除
      function delpayAll () {
        var datas = $('#table tbody td .layui-form-checked')
        var ids = []
        datas.each(function(index, element){
          var id = $(this).data('id')
          ids.push(id)
        })

        var str = ids.join(',');
        var count = ids.length
        //window.location.href='{:url("billDel")}?id='+str;
        layer.confirm('你确定要删除这'+ count + '项吗', function(){
          $.post('{:url("billpayDel")}', { id: str}, function(r){
            if (r.info) {
              layer.msg(r.info)
              location.reload()
            }else{
              layer.msg(r.error)
              location.reload()
            }
          })
        })
      }
      //批量打印
      function printing () {
        var datas = $('#table tbody td .layui-form-checked')
        var ids = []
        datas.each(function(index, element){
          var id = $(this).data('id')
          ids.push(id)
        })

        var str = ids.join(',');
        var count = ids.length
        layer.confirm('你确定要打印这'+ count + '项吗', function(){
          $.post('{:url("admin/Bill/Printing")}', { id: str}, function(r){
            if (r.info) {
              layer.msg(r.info)
              location.reload()
            }else{
              layer.msg(r.error)
              location.reload()
            }
          })
        })
      }
      
      //批量同步
      function billUpload(){
        var datas = $('#table tbody td .layui-form-checked')
        var ids = []
        datas.each(function(index, element){
          var id = $(this).data('id')
          ids.push(id)
        })

        var str = ids.join(',');
        
        var count = ids.length
        
        if(count=="0"){
            layer.msg("请选择要同步的账单");
            return ;
        }
        //window.location.href="{:url("billUpload")}?id="+str;
        layer.confirm('你确定要同步这'+ count + '项吗', function(){
          $.post('{:url("billUpload")}', { id: str}, function(r){
            if (r.info) {
              layer.msg(r.info)
              setTimeout(function (){
                	window.location.reload();
                }, 1000)
            }else{
              layer.msg(r.error)
              setTimeout(function (){
                	window.location.reload();
                }, 1000)
            }
          })
        })
      }

      //批量导出
      function exportExcel(exportid){
        var datas = $('#table tbody td .layui-form-checked')
        var ids = []
        datas.each(function(index, element){
          var id = $(this).data('id')
          ids.push(id)
        })

        var str = ids.join(',');
        var count = ids.length
        var url = "{:url('admin/trade/export')}?id=" + str +'&export=' + exportid
        console.log(url);
        layer.open({
          type: 2,
          title: '批量导出账单',
          shadeClose: true,
          shade: 0.8,
          area: ['80%', '95%'],
          content: url //iframe的url
        }); 
      }

      //一键收款
      function onekeyBillList() {
        var datas = $('#table tbody td .layui-form-checked')
        var ids = []
        datas.each(function(index, element){
          var id = $(this).data('id')
          ids.push(id)
        })

        var str = ids.join(',');
        var count = ids.length
       
        var url = "{:url('onekeyBillList')}?id=" + str
        layer.open({
          type: 2,
          title: '一键收款',
          shadeClose: true,
          shade: 0.8,
          area: ['60%', '70%'],
          content: url //iframe的url
        }); 
      }

      //一键收款
      function onekeyBillList2() {
        var datas = $('#table tbody td .layui-form-checked')
        var ids = []
        datas.each(function(index, element){
          var id = $(this).data('id')
          ids.push(id)
        })

        var str = ids.join(',');
        var count = ids.length
       
        var url = "{:url('onekeyBillList2')}?id=" + str
        layer.open({
          type: 2,
          title: '一键收款',
          shadeClose: true,
          shade: 0.8,
          area: ['60%', '70%'],
          content: url //iframe的url
          
        }); 
      }


      //批量开票
      function invoice(){
        if(confirm('是否确定开票?')){
          var datas = $('#table tbody td .layui-form-checked')
          var ids = []
          datas.each(function(index, element){
            var id = $(this).data('id')
            ids.push(id)
          })

          var str = ids.join(',');
          var count = ids.length
          var url = "{:url('admin/invoice/invoice')}?id=" + str
          layer.open({
            type: 2,
            title: '批量开票',
            shadeClose: true,
            shade: 0.8,
            area: ['80%', '95%'],
            content: url //iframe的url
          }); 
        }
        
        
      }
    </script>
    <!-- 多条件查询 -->
    <script>

      layui.use(['form'], function() {
          var form = layui.form
          $("#foundkeycommunity").blur(function(){
            var _this = $(this);
            var foundkeycommunity=_this.val();
            //layer.alert(foundkeycommunity);
            var url = "{:url('admin/Roominfo/fetchdata')}"
              $.post(url, {community_name: foundkeycommunity, type: 5}, function(data) {
                  //console.log(data);
                  $('#community_id').html("")
                  var option = "<option value=''>小区</option>"
                  $('#community_id').append(option)
                  for (var i = 0; i < data.length; i++) {
                  option = "<option value='" + data[i]["community_id"] + "'>" + data[i]["community_name"] + "</option>"
                  $('#community_id').append(option)
                  }
                  
                  form.render('select')
              })
          })
          form.on('select(community_id)', function(f){
              var url = "{:url('admin/Roominfo/fetchdata')}"
              $.post(url, {community_id: f.value, type: 1}, function(data) {
                console.log(data);
                  $('#group').html("")
                  var option = "<option value=''>组团</option>"
                  $('#group').append(option)
                  for (var i = 0; i < data.length; i++) {
                  option = "<option value='" + data[i] + "'>" + data[i] + "</option>"
                  $('#group').append(option)
                  }
                  
                  form.render('select')
              })
              
              $('#community_id').data('community_id', f.value)
          })

          form.on('select(group)', function(f){
              var data_community = $('#community_id').data('community_id')
              var get_community = "<?php if (isset($community_id)) { echo $community_id;}?>"
              var community_id = typeof data_community === 'undefined' ? get_community : data_community
              var url = "{:url('admin/Roominfo/fetchdata')}"
              $.post(url, {community_id: community_id, group: f.value, type: 2}, function(data) {
                  $('#building').html("")
                  var option = "<option value=''>楼栋</option>"
                  $('#building').append(option)
                  for (var i = 0; i < data.length; i++) {
                      option = "<option value='" + data[i] + "'>" + data[i] + "</option>"
                      $('#building').append(option)
                  }
                  $('#group').data('group', f.value)
                  form.render('select')
              })
          })
  
          form.on('select(building)', function(f){
              var data_community = $('#community_id').data('community_id')
              var get_community = "<?php if (isset($community_id)) { echo $community_id;}?>"
              var community_id = typeof data_community === 'undefined' ? get_community : data_community

              var data_group = $('#group').data('group')
              var get_group = "<?php if (isset($group)) { echo $group;}?>"
              var group = typeof data_group === 'undefined' ? get_group : data_group

              var url = "{:url('admin/Roominfo/fetchdata')}"
              $.post(url, {building: f.value, community_id: community_id, group: group, type: 3}, function(data) {
              $('#unit').html("")
              var option = "<option value=''>单元</option>"
              $('#unit').append(option)
              for (var i = 0; i < data.length; i++) {
                  option = "<option value='" + data[i] + "'>" + data[i] + "</option>"
                  $('#unit').append(option)
              }
              $('#building').data('building', f.value)
              form.render('select')
              })
          })
  
          form.on('select(unit)', function(f){
              var data_community = $('#community_id').data('community_id')
              var get_community = "<?php if (isset($community_id)) { echo $community_id;}?>"
              var community_id = typeof data_community === 'undefined' ? get_community : data_community

              var data_group = $('#group').data('group')
              var get_group = "<?php if (isset($group)) { echo $group;}?>"
              var group = typeof data_group === 'undefined' ? get_group : data_group

              var data_building = $('#building').data('building')
              var get_building = "<?php if (isset($building)) { echo $building;}?>"
              var building = typeof data_building === 'undefined' ? get_building : data_building
      
              var url = "{:url('admin/Roominfo/fetchdata')}"
              $.post(url, {unit: f.value, community_id: community_id, group: group, building: building, type: 4}, function(data) {
              $('#room').html("")
              var option = "<option value=''>房间</option>"
              $('#room').append(option)
              for (var i = 0; i < data.length; i++) {
                  option = "<option value='" + data[i] + "'>" + data[i] + "</option>"
                  $('#room').append(option)
              }
              $('#unit').data('unit', f.value)
              form.render('select')
              })
          })
  
      })
  </script>
    <script>var _hmt = _hmt || []; (function() {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
      })();</script>
  </body>

</html>